/*
 * lab2.fx
 *
 * Created on 23.10.2009, 22:30:50
 */

/*
 * Main.fx
 *
 * Created on 23.09.2009, 20:06:22
 */

package src.javafx179labs.dergunov.lab2;

import javafx.stage.Stage;
import javafx.scene.*;
import javafx.scene.Group;
import javafx.scene.control.Button;
import javafx.ext.swing.SwingTextField;

//********************************************

var list: Group[] = [];

function order (seq: Group[]) {var inc = 0; for (elem in list) { elem.translateY = inc; inc += 30; } return seq; }

function create_control (text:String) {
    var txt = text;
    var mode: Group;
    var edit: Group;
    var binding: Group;


    var edit_field = SwingTextField {
        columns: 30
        text: txt
    }

    var main = Group {
        content: [
                SwingTextField {
                    editable: false
                    columns: 25
                    text: bind txt
                },

                Button {
                    text: "edit"
                    height: 25
                    width: 50
                    layoutX: 290
                    action: function () {
                        edit_field.text = txt;
                        mode = edit
                    }
                },

                 Button {
                    text: "delete"
                    height: 25
                    width: 50
                    layoutX: 410
                    action: function ():Void {
                        list = list[x | x != binding];
                    }
           }

        ]
    }

    edit = Group {
        content: [
                edit_field,

                Button {
                    text: "ok"
                    height: 25
                    width: 50
                    layoutX: 290
                    action: function () {
                        txt = edit_field.text;
                        mode = main
                    }
                },

                Button {
                    text: "cancel"
                    height: 25
                    width: 50
                    layoutX: 350
                    action: function () {
                        mode = main
                    }
                }
        ]
    }

    mode = main;

    binding = Group {
        content: bind [mode]
    }
     return binding
 }

var add_field = SwingTextField {
    columns: 30
}

list = [create_control("Тимотэээ^^"), create_control("Десу~"), create_control(">_<")];

Stage {
    title: "Desu~"
    width: 1024
    height: 768
    scene: Scene {
        content: [add_field, Button {
                        text: "add"
                        height: 25
                        width: 50
                        layoutX: 290
                    action: function () :Void { insert create_control(add_field.text) into list; }},
                    Group { translateY: 30 content: bind order(list)}]
      }
  }